<template>
	<view>
		<plus-network :isConnected="isConnected">
			<view class="activa">
				<view class="activa_title">
					<text :class="[fontload(lang)]">{{ $t('activateion.activatesoft') }}</text>
				</view>

				<view class="input-group" :class="[layout(lang)]">
					<view class="input-layout border-b font-30">
						<label>
							<text :class="[fontload(lang)]">{{ $t('activateion.usernum') }}</text>
						</label>
						<input type="number" class="input" @input="onkahao" :value="kahaonum" />
					</view>

					<view class="input-layout font-30">
						<label>
							<text :class="[fontload(lang)]">{{ $t('activateion.password') }}</text>
						</label>
						<input type="number" password="true" class="input" @input="onkami" :value="kaminum" />
					</view>
				</view>
				<button class="button-layout  font-30" @click="onaction(0)">
					<text :class="[fontload(lang)]">{{ $t('activateion.action') }}</text>
				</button>
				
				
				<view class="button-group">
					<view class="two-button">
						<button class="on-trial font-30" @click="link('ontrial')">
							<text :class="[fontload(lang)]">{{ $t('activateion.ontrial') }}</text>
						</button>
					</view>
					<view class="shopping">
						<button class="shopping-button font-30" v-if="jshenhe" @click="kefulink">
							<text :class="[fontload(lang)]">{{ $t('activateion.buycode') }}</text>
							<image class="shopping-button_image" src="https://tongyongjiakao-1307163845.cos.ap-shanghai.myqcloud.com/used_img/payicon.png"></image>
						</button>
						<button class="shopping-button font-30" v-else @click="link('buycode')">
							<text :class="[fontload(lang)]">{{ $t('activateion.buycode') }}</text>
							<image class="shopping-button_image" src="https://tongyongjiakao-1307163845.cos.ap-shanghai.myqcloud.com/used_img/payicon.png"></image>
						</button>
					</view>
				</view>
				<block v-if="jshenhe">
					<button class="button-agent font-30" @click="kefulink" >
						<text :class="[fontload(lang)]">联系客服</text>
					</button>
					
				</block>
				<block v-else>
					<button class="button-agent font-30" @click="link('/ucenter/shopcart')">
						<text :class="[fontload(lang)]">{{ $t('activateion.agent') }}</text>
					</button>
				</block>
				

				

				<view class="booter">
					<view class="regulations">
						<text @click="openweb" :class="[fontload(lang)]">{{ $t('activateion.regulations') }}</text>
					</view>
					<view class="agree" :class="[layout(lang)]">
						<checkbox-group @change="setDoamin">
							<label>
								<!-- <radio name="paytype" value="agreementSelected" :checked="racheck" color="#0BD34E" checked="true" class="payviewradio"></radio> -->
								<checkbox  name="paytype" :checked="racheck" color="#0BD34E"
									class="payviewradio"></checkbox>
								<text :class="[fontload(lang)]">{{ $t('activateion.agree') }}</text>
							</label>
						</checkbox-group>
					</view>
				</view>
			</view>
		</plus-network>
		<u-popup v-model="wxloginshow" mode="bottom" :mask-close-able="false">
			<view class="loginview">
				<view class="loginbtnview">
					<view class="loginbtnk">
						
						<button class="weichat" open-type="getUserInfo" @click="wxlogin()">
							<u-icon name="weixin-fill" color="#ffffff"></u-icon>
							<text>微信登陆</text>
						</button>
					</view>
					
					<view class="loginbtnk" v-show="loginshenhe">
						<button class="apple" @click="applogin()">
							<!-- <u-icon name="weixin-fill" color="#00000"></u-icon> -->
							<text>&nbsp;</text>
						</button>
					</view>
					<!-- #ifdef APP-PLUS -->
					<!-- #endif -->
				</view>
				<view class="booter clearfix">
					<view class="regulations">
						<text @click="openweb" :class="[fontload(lang)]">{{ $t('activateion.regulations') }}</text>
					</view>
					<view class="agree" :class="[layout(lang)]">
						<checkbox-group @change="setDoamin">
							<label>
								<!-- <radio name="paytype" value="agreementSelected" :checked="racheck" color="#0BD34E" checked="true" class="payviewradio"></radio> -->
								<checkbox name="paytype" :checked="racheck" color="#0BD34E" 
									class="payviewradio"></checkbox>
								<text :class="[fontload(lang)]">{{ $t('activateion.agree') }}</text>
							</label>
						</checkbox-group>
					</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	//接口
	import {
		siteurl,
		wxlogin_api,
		jihuo_api, //地址添加修改接口
		updpk_api, //版本信息
		wxminilogin_api
	} from '@/api/index';



	export default {
		data() {
			return {
				lang: this.$i18n.locale,
				kahaonum: '',
				kaminum: '',
				isConnected: true, //判断网络状态
				wxloginshow: false,
				shenhe: false, //审核状态
				cartype: 'jiashizheng',
				tmpimg: '',
				anleanniu: true,
				loginshenhe: true,
				racheck: false, //选择用户协议， 如果没有勾选false
				jshenhe:false,
				kftel:'15688353919'
			};
		},
		onBackPress(){
			return false;
		},
		onShow: function() {
			console.log("home-监听页面显示");
			var that = this;
			
			that.userstat();

			//执行频率：game（20ms/次）、ui（60ms/次）、normal（200ms/次）
			var ontrials = uni.getStorageSync('ontrial_time'); //tiyan_times
			console.log("ontrials", ontrials)

			var tiyan_times = uni.getStorageSync('tiyan_times'); //tiyan_times
			console.log("tiyan_times", tiyan_times)
			
			

		},
		onLoad() {
			var that = this;
			
			//判断机型
			var typeterminals = that.$kterminal;
			console.log("typeterminals*****", typeterminals);
			if (typeterminals == 'android') {
				that.shenhe = true;
				that.loginshenhe = false;
			}
			if (typeterminals == 'ios') {
				that.loginshenhe = true;
			}
			
			const racheckvalue = uni.getStorageSync('racheck');
			if (racheckvalue) {
				that.racheck = true
			}
			
			that.tekserws();
			
			// #ifdef APP-PLUS
			that.banben()
			// #endif
			//页面不要满屏
			//判断网络状态
			uni.getNetworkType({
				success: res => {
					if (res.networkType == 'none') {
						this.isConnected = false;
					} else {
						this.isConnected = true;
					}
				}
			});
			uni.onNetworkStatusChange(res => {
				this.isConnected = res.isConnected;
			});

			uni.getStorage({
				key: 'exam_type',
				success: function(res) {
					that.cartype = res.data;
					console.log('已经设置过了，不要重复设置，如果想重复设置，请清理kem——type');
				},
				fail(e) {
					console.log('没有设置科目，请继续设置');
					uni.navigateTo({
						url: '../setting/setting'
					});
				}
			});

			//判断登陆状态
			uni.getStorage({
				key: 'user_infos',
				success: function(res) {
					console.log(res, '=====');
					that.wxloginshow = false;
					//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
					// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理

					var userstatus = res.data.userstatus;
					//var userstatus = -2;
					console.log(userstatus);
					if (userstatus == 'undefined') {
						console.log('re login');
						uni.removeStorage({
							key: 'user_infos',
							success: function(res) {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.登录信息已超时'),
									success: function(res) {
										that.wxloginshow = true;
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							}
						});
						return false;
					}



					if (userstatus == -1) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已禁用'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}
					if (userstatus == -3) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已出现问题'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}
					if (userstatus === -2) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已到期'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}

					if (userstatus == 0) {
						//禁用状态
						// uni.showModal({
						// 	title: that.$t('jihuo.提示'),
						// 	content: that.$t('jihuo.您不是会员'),
						// 	success: function(res) {
						// 		if (res.confirm) {
						// 			console.log('用户点击确定');
						// 		} else if (res.cancel) {
						// 			console.log('用户点击取消');
						// 		}
						// 	}
						// });
						return false;
					}
					if (userstatus > 0) {
						//判断时间是否到？
						let timestamp = new Date().getTime();
						let jieshuriqi = res.data.jieshuriqi;
						console.log("日期比较", timestamp, jieshuriqi)
						if (jieshuriqi < timestamp) {
							//时间到期
							if (that.isConnected == false) {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.请联网后重新激活'),
									success: function(res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							} else {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.您的账号已到期'),
									success: function(res) {
										//更改用户session信息
										const value = uni.getStorageSync('user_infos');
										var obj = JSON.parse(
											'{"openid":"' +
											value.openid +
											'","unionid": "' +
											value.unionid +
											'","kaishiriqi":"' +
											value.kaishiriqi +
											'","jieshuriqi":"' +
											value.jieshuriqi +
											'","userstatus":"' +
											-2 +
											'","jihuofangshi":"' +
											value.jihuofangshi +
											'","nick_name":"' +
											value.nick_name +
											'","pic_url":"' +
											value.pic_url +
											'","uid":"' +
											value.uid +
											'","dailijibie":"' +
											value.dailijibie +
											'"}'
										);

										if (res.confirm) {
											console.log('用户点击确定');
											uni.setStorage({
												key: 'user_infos',
										  data: obj,
												success: function() {
										   console.log('success');
													// uni.reLaunch({
													// 	url:"../index/start"
													// })
												}
											});
										} else if (res.cancel) {
											console.log('用户点击取消');
											uni.setStorage({
												key: 'user_infos',
												data: obj,
										 	success: function() {
													console.log('success');
													// uni.reLaunch({
													// 	url:"../index/start"
													// })
												}
											});
										}
									}
								});
							}
						} else {
							//直接跳转到首页
							that.tiaozhuan();
						}
					}
				},
				fail(err) {
					that.wxloginshow = true;
				}
			});
		},
		methods: {
			tekserws: function(){
				var that = this;
				that.http({
					url: "jia.json",
					method: 'GET',
					header: {
						// 'content-type': 'application/x-www-form-urlencoded'
						'content-type': 'application/json'
					},
					data: {},
					success: resmm => {
						console.log(resmm);
						// that.teks = resmm.tekserw;
						//that.jshenhe = resmm.fasker;
						
						var jvalue = resmm.fasker
						
						var typeterminals = that.$kterminal;
						console.log("typeterminals----=",typeterminals)
						if(typeterminals == 'android'){
							that.jshenhe = false;
							uni.setStorageSync('jshenhe', false);
						}else{
							that.jshenhe = jvalue;
							uni.setStorageSync('jshenhe', jvalue);
						}
						
						//that.jshenhe = true;
						that.kftel = resmm.kefu;
						
						
						
					},
					fail: err => {
						console.log(err);
					}
				
				});
			},
			kefulink(){
				var that = this;
				uni.makePhoneCall({
					phoneNumber: that.kftel
				});
			},
			applepay: function(){
				var that = this;
				console.log("jinru apple pay")
				if (that.racheck === false) {
					uni.showModal({
						content: '请登陆前同意用户协议',
						showCancel: false
					});
					return false;
				} else {
					uni.navigateTo({
						url:'./applepay'
					})
					// uni.redirectTo({
					// 	url:'./applepay'
					// })
				}
				
			},
			setDoamin: function() {
				var that = this;

				this.racheck = !this.racheck;

				console.log("chack ===" + that.racheck);

				// if(that.racheck == 1){
				// 	that.racheck = 0;
				// }else{
				// 	that.racheck = 1;
				// }
			},
			userstat: function() {
				var that = this;
				uni.getStorage({
					key: 'user_infos',
					success: function(res) {

						var uinfo = res.data;

						var stystems = null;
						// #ifdef APP-PLUS
						uni.getSystemInfo({
							success: function(res) {
								if (res.platform == 'ios') {
									console.log('苹果机器');
									stystems = 'iphone';
								} else {
									console.log('不是苹果机器222');
									stystems = 'android';
								}
								console.log(res.platform);
							}
						});
						// #endif

						// #ifdef MP-WEIXIN
						stystems = 'miniprog';
						// #endif

						// #ifdef MP-WEIXIN
						var devid = '100010010';
						var system_info = 'miniprogram'
						// #endif
						// #ifdef APP-PLUS
						var devid = plus.device.uuid;
						var system_info = plus.device.model
						// #endif
						var versionsss = '1.0.0';
						that.http({
							url: wxlogin_api,
							method: 'POST',
							header: {
								// 'content-type': 'application/x-www-form-urlencoded'
								'content-type': 'application/json'
							},
							data: {
								openid: uinfo.openid,
								unionid: uinfo.unionid,
								nick_name: uinfo.nick_name,
								pic_url: uinfo.pic_url,
								sex: uinfo.gender,
								gexing: null,
								devid: devid,
								system: stystems,
								system_info: system_info,
								version: versionsss,
								lastuptime: 0,
								lang: that.lang,
								apple_openid: null,
								apple_name: null,
								apple_famila: null,
								apple_email: null
							},
							success: resu => {
								console.log(resu);
								console.log(JSON.stringify(resu));

								//存储openid
								that.usersetinfo(resu, uinfo.openid, uinfo, false);


								//that.wxloginshow = false;
								//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
								// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
								//var userstatus = res.userstatus;
								//var userstatus = -2;




							},
							fail: err => {
								console.log(err);
							}

						});
					},
					fail() {
						//返回登录按钮，重新微信登录
						uni.hideLoading();
					}
				});
			},
			tiaozhuan: function(no) {
				var that = this;
				uni.getStorage({
					key: 'exam_type',
					success: function(res) {
						console.log('已经设置过了，不要重复设置，如果想重复设置，请清理kem——type');
						if (res.data == 'zigezheng') {
							if (no == true) {
								uni.reLaunch({
									url: '../index/qualification?alert=1'
								});
							} else {
								uni.reLaunch({
									url: '../index/qualification'
								});
							}

						} else {
							if (no == true) {
								uni.reLaunch({
									url: '../index/index?alert=1'
								});
							} else {
								uni.reLaunch({
									url: '../index/index'
								});
							}

						}
					},
					fail(e) {
						console.log('没有设置科目，请继续设置');
						uni.reLaunch({
							url: '../setting/setting'
						});
					}
				});
			},
			openweb: function() {
				var that = this;
				uni.navigateTo({
					url: '../template/index'
				});
			},
			banben: function() {
				var that = this;
				console.log("进入版本信息了")
				that.https({
					url: updpk_api,
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {},
					success: res => {
						console.log(res);
						let versi = res.versionInfo.type;
						console.log('versi=', versi);
						var typeterminals = that.$kterminal;
						if (versi == 1) {
							if (typeterminals == 'android') {
								that.shenhe = true;
								
							} else {
								that.shenhe = false;
								that.loginshenhe = false
							}
							//that.shenhe = false;
						} else {
							that.loginshenhe = true;
							that.shenhe = true;
							//that.racheck = true;
						}



						// {
						// 	"versionInfo": {
						// 		"apkname": "tongyongjiakao.apk",
						// 		"version": "0.0.12",
						// 		"desc": "版本更新了，更新了更新了，更新了很多。。。。。。",
						// 		"downurl": "http://www.tongyongjiakao.com/jiaxiao/tongyongjiakao_test.apk",
						// 		"type": 0,
						// 		"updatedate": 1641919303528
						// 	}
						// }
					},
					fail: err => {
						console.log(err);
					}
				});
			},
			//微信登陆
			wxlogin: function() {
				var that = this;

				if (that.racheck === false) {
					uni.showModal({
						content: '请登陆前同意用户协议',
						showCancel: false
					});
					return false;
				} else {
					uni.setStorageSync('racheck', 'true')
					that.anleanniu = false;



					// #ifdef MP-WEIXIN
					var devid = '100010010';
					var system_info = 'miniprogram'

					stystems = 'miniprog';
					uni.login({
			 		provider: 'weixin',
						success: function(loginRes) {
					  console.log("loginRes", loginRes);
							var code = loginRes.code;
							console.log("code", code);



							that.http({
								url: wxminilogin_api,
								method: 'POST',
								header: {
				 				// 'content-type': 'application/x-www-form-urlencoded'
									'content-type': 'application/json'
								},
								data: {
									jscode: code
								},
								success: res => {
									console.log(res);
									console.log(JSON.stringify(res));
									//login_result: "{"session_key":"d3UnTWLvO6Uq3sbbkU8oKw==","openid":"oZelb44C11VsTsrAW_kAhi5Qcwt4","unionid":"oYR7U5yjBVOTr-PI09kMQ0k6iwBs"}"
					  		//存储openid
									// 获取openid后开启
									//that.usersetinfo(res,openid,true);
									var ures = JSON.parse(res.login_result);
									console.log("ures=", ures);

									uni.getUserInfo({
										success: info => {
											console.log(JSON.stringify(info));
											that.wxloginshow = false;

											var openids = ures.openid;
											var unionids = ures.unionid; //unionid
											// 与服务器交互将数据提交到服务端数据库
											that.http({
												url: wxlogin_api,
												method: 'POST',
												header: {
													// 'content-type': 'application/x-www-form-urlencoded'
													'content-type': 'application/json'
												},
												data: {
													openid: openids,
													unionid: unionids,
													nick_name: info.userInfo.nickName,
													pic_url: info.userInfo.avatarUrl,
													sex: info.userInfo.gender,
													gexing: null,
													devid: devid,
													system: stystems,
													system_info: system_info,
													version: '1.0.0',
													lastuptime: 0,
													lang: that.lang,

													apple_openid: null,
													apple_name: null,
													apple_famila: null,
													apple_email: null

												},
												success: resmm => {
													console.log(resmm);
													console.log(JSON
														.stringify(
															resmm));
													that.usersetinfo(
														resmm,
														openids,
														info, true,
														unionids);
													//存储openid

												},
												fail: err => {
													console.log(err);
												}

											});
										},
										fail: () => {
											console.log('微信登录授权失败1');
											uni.showToast({
												title: '服务出现异常'
											});
										}
									});

								},
								fail: err => {
									console.log(err);

								}

							});
							//console.log(loginRes.authResult);
						},
						fail: ret => {
							console.log(ret);
							console.log('微信登录授权失败2');
							that.anleanniu = true;
							uni.showModal({
								content: '请登陆微信后再使用微信登陆',
								showCancel: false
							});

						},
						complete: () => {
							uni.hideLoading();
						}
					});
					// #endif



					var stystems = null;
					// #ifdef APP-PLUS
					// ifdef MP-WEIXIN
					uni.getSystemInfo({
						success: function(res) {
							if (res.platform == 'ios') {
								console.log('苹果机器');
								stystems = 'iphone';
							} else {
								console.log('不是苹果机器222');
								stystems = 'android';
							}
							console.log(res.platform);
						}
					});

					uni.login({
						provider: 'weixin',
						success: res => {
							console.log(JSON.stringify(res));
							// #ifdef APP-PLUS
							var devid = plus.device.uuid;
							var system_info = plus.device.model
							// #endif

							uni.getUserInfo({
								success: info => {
									console.log(JSON.stringify(info));
									that.wxloginshow = false;

									var openid = info.userInfo.openId;
									console.log("info.userInfo", info.userInfo);
									// 与服务器交互将数据提交到服务端数据库
									that.http({
										url: wxlogin_api,
										method: 'POST',
										header: {
											// 'content-type': 'application/x-www-form-urlencoded'
											'content-type': 'application/json'
										},
										data: {
											openid: openid,
											unionid: info.userInfo.unionId,
											nick_name: info.userInfo.nickName,
											pic_url: info.userInfo.avatarUrl,

											sex: info.userInfo.gender,
											gexing: null,
											devid: devid,

											system: stystems,

											system_info: system_info,
											version: '1.0.0',
											lastuptime: 0,
											lang: that.lang,

											apple_openid: null,
											apple_name: null,
											apple_famila: null,
											apple_email: null
											// console.log("Model: " + plus.device.model);
											// //获取设备的生产厂商
											// console.log("Vendor: " + plus.device.vendor);

											// unionid,
											// openid,
											// nick_name,	昵称
											// pic_url,
											// sex,		性别
											// gexing,		个性签名
											// devid,		硬件序列号
											// system,		设备类型:miniprog,android,iphone
											// system_info,	附加信息
											// version,	1.1.0	软件版本号
											// lastuptime,	上次题库更新时间戳
											// lang,		kz,ug,cn
											// apple_openid,
											// apple_name,
											// apple_famila,
											// apple_email
										},
										success: res => {
											console.log(res);
											console.log(JSON.stringify(res));
											that.usersetinfo(res, openid, info,
												true, info.userInfo.unionId);
											//存储openid

										},
										fail: err => {
											console.log(err);
											that.anleanniu = false;
										}

									});
								},
								fail: () => {
									console.log('微信登录授权失败1');
									that.anleanniu = false;
									uni.showToast({
										title: '服务器出现异常'
									});
								}
							});



						},
						fail: ret => {
							console.log(ret);
							console.log('微信登录授权失败2');
							that.anleanniu = true;
							uni.showModal({
								content: '请登陆微信后再使用微信登陆',
								showCancel: false
							});
						},
						complete: () => {
							uni.hideLoading();
						}
					});
					// #endif
				}
			},
			usersetinfo: function(res, openid, info, loginstatu, unionids) {
				var that = this;
				console.log("info", info);
				uni.setStorageSync('openid', openid);
				if (loginstatu) {
					var obj = JSON.parse(
						'{"openid":"' +
						openid +
						'","unionid": "' +
						unionids +
						'","kaishiriqi":"' +
						res.kaishiriqi +
						'","jieshuriqi":"' +
						res.jieshuriqi +
						'","userstatus":"' +
						res.userstatus +
						'","jihuofangshi":"' +
						res.jihuofangshi +
						'","nick_name":"' +
						info.userInfo.nickName +
						'","pic_url":"' +
						info.userInfo.avatarUrl +
						'","uid":"' +
						res.uid +
						'","dailijibie":"' +
						res.dailijibie +
						'"}'
					);
				} else {
					var obj = JSON.parse(
						'{"openid":"' +
						openid +
						'","unionid": "' +
						info.unionid +
						'","kaishiriqi":"' +
						res.kaishiriqi +
						'","jieshuriqi":"' +
						res.jieshuriqi +
						'","userstatus":"' +
						res.userstatus +
						'","jihuofangshi":"' +
						res.jihuofangshi +
						'","nick_name":"' +
						info.nickname +
						'","pic_url":"' +
						info.avatarurl +
						'","uid":"' +
						res.uid +
						'","dailijibie":"' +
						res.dailijibie +
						'"}'
					);
				}

				uni.setStorageSync('user_infos', obj);
				if (loginstatu == true) {
					uni.showToast({
						title: '登陆成功',
						mask: false,
						duration: 1500
					});
				}
				that.anleanniu = true;
				that.wxloginshow = false;
				//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
				// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
				var userstatus = res.userstatus;
				//var userstatus = -2;
				if (userstatus == -1) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已禁用'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}
				if (userstatus == -3) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已出现问题'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}
				if (userstatus == -2) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已到期'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}

				if (userstatus == 0) {
					//禁用状态

					return false;
				}
				if (userstatus > 0) {
					//判断时间是否到？
					let timestamp = new Date().getTime();
					let jieshuriqi = res.jieshuriqi;
					if (jieshuriqi < timestamp) {
						//that.tiaozhuan();
						//时间到期
						if (that.isConnected == false) {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.请联网后重新激活'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.您的账号已到期'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					} else {
						//直接跳转到首页
						that.tiaozhuan();
					}
				}
			},
			/**
			 * 苹果用户登陆
			 * */
			// 苹果登录
			applogin: function() {
				var that = this;
				if (that.racheck === false) {
					uni.showModal({
						content: '请登陆前同意用户协议',
						showCancel: false
					});
					return false;
				} else {
				uni.showLoading({
					title: '加载中'
				});

				uni.login({
					provider: 'apple',
					success: function(loginRes) {
						console.log("loginRes", loginRes)
						// 登录成功
						uni.getUserInfo({
							provider: 'apple',
							success(oauth) {
								// 获取用户信息成功

								console.log('oauth info');
								console.log(oauth);
								console.log('oauth');
								console.log(oauth);
								var openid = '';
								var name = 'apple';
								var famila = '';
								var email = '';
								var formdata = oauth.userInfo;

								openid = formdata.openId;
								if (formdata.fullName.giveName) {
									name = formdata.fullName.giveName;
								}
								if (formdata.fullName.familyName) {
									famila = formdata.fullName.familyName;
								}

								if (formdata.email) {
									email = formdata.email;
								}
								var usrepic = siteurl + '/ios_logo.png';

								console.log(openid, name, famila, email);
								console.log('formdata');
								console.log(formdata);

								that.http({
									url: wxlogin_api,
									method: 'POST',
									header: {
										// 'content-type': 'application/x-www-form-urlencoded'
										'content-type': 'application/json'
									},
									data: {
										openid: openid,
										unionid: openid, //生成
										nick_name: name,
										pic_url: usrepic,
										sex: 1,
										gexing: null,
										devid: plus.device.uuid,
										
										system: 'stystemsios',
										system_info: 'system_infoios',
										version: '1.0.0',
										lang: that.lang,
										
										lastuptime: 0,
										apple_openid: openid,
										apple_name: name,
										apple_famila: famila,
										apple_email: email
										//苹果登录

										// unionid,
										// openid,
										// nick_name,	昵称
										// pic_url,
										// sex,		性别
										// gexing,		个性签名
										// devid,		硬件序列号
										// system,		设备类型:miniprog,android,iphone
										// system_info,	附加信息
										// version,	1.1.0	软件版本号
										// lastuptime,	上次题库更新时间戳
										// lang,		kz,ug,cn
										// apple_openid,
										// apple_name,
										// apple_famila,
										// apple_email
									},
									success: res => {
										console.log(res);
										console.log(JSON.stringify(res));
										//kaishiriqi --开始日期
										//jieshuriqi --结束日期
										// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
										//存储openid
										uni.setStorageSync('openid', openid);

										var obj = JSON.parse(
											'{"openid":"' +
											openid +
											'","unionid": "' +
											openid +
											'","kaishiriqi":"' +
											res.kaishiriqi +
											'","jieshuriqi":"' +
											res.jieshuriqi +
											'","userstatus":"' +
											res.userstatus +
											'","jihuofangshi":"' +
											res.jihuofangshi +
											'","nick_name":"apple ","pic_url":"' +
											usrepic +
											'","uid":"' +
											res.uid +
											'","dailijibie":"' +
											res.dailijibie +
											'"}'
										);
										uni.setStorageSync('user_infos', obj);

										uni.showToast({
											title: '登陆成功',
											mask: false,
											duration: 1500
										});
										that.wxloginshow = false;
										//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
										// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
										var userstatus = res.userstatus;
										//var userstatus = -2;
										if (userstatus == -1) {
											//禁用状态
											uni.showModal({
												title: that.$t('jihuo.提示'),
												content: that.$t(
													'jihuo.您的账号已禁用'),
												success: function(res) {
													if (res.confirm) {
														console.log(
															'用户点击确定');
													} else if (res
														.cancel) {
														console.log(
															'用户点击取消');
													}
												}
											});
											return false;
										}
										if (userstatus == -3) {
											//禁用状态
											uni.showModal({
												title: that.$t('jihuo.提示'),
												content: that.$t(
													'jihuo.您的账号已出现问题'),
												success: function(res) {
													if (res.confirm) {
														console.log(
															'用户点击确定');
													} else if (res
														.cancel) {
														console.log(
															'用户点击取消');
													}
												}
											});
											return false;
										}
										if (userstatus == -2) {
											//禁用状态
											uni.showModal({
												title: that.$t('jihuo.提示'),
												content: that.$t(
													'jihuo.您的账号已到期'),
												success: function(res) {
													if (res.confirm) {
														console.log(
															'用户点击确定');
													} else if (res
														.cancel) {
														console.log(
															'用户点击取消');
													}
												}
											});
											return false;
										}

										if (userstatus == 0) {

										}
										if (userstatus > 0) {
											//判断时间是否到？
											let timestamp = new Date().getTime();
											let jieshuriqi = res.jieshuriqi;
											if (jieshuriqi < timestamp) {
												//时间到期
												if (that.isConnected == false) {
													uni.showModal({
														title: that.$t(
															'jihuo.提示'),
														content: that.$t(
															'jihuo.请联网后重新激活'
															),
														success: function(
														res) {
															if (res
																.confirm) {
																console
																	.log(
																		'用户点击确定'
																		);
															} else if (res
																.cancel) {
																console
																	.log(
																		'用户点击取消'
																		);
															}
														}
													});
												} else {
													uni.showModal({
														title: that.$t(
															'jihuo.提示'),
														content: that.$t(
															'jihuo.您的账号已到期'
															),
														success: function(
														res) {
															if (res
																.confirm) {
																console
																	.log(
																		'用户点击确定'
																		);
															} else if (res
																.cancel) {
																console
																	.log(
																		'用户点击取消'
																		);
															}
														}
													});
												}
											} else {
												//直接跳转到首页
												that.tiaozhuan();
											}
										}
									},
									fail: err => {
										console.log(err);
									}
								});


							}
						});
					},
					fail: function(err) {
						console.log("e=", err)
						// 登录失败
						uni.showModal({
							content: '登录失败！请用微信一键登录方式登录',
							showCancel: false
						});
					},
					complete: function() {
						uni.hideLoading();
					}
				});
				}
				console.log('888');
				// 判断是 iOS13版本
			},
			//获取卡号
			onkahao(e) {
				this.kahaonum = e.target.value;
			},
			onkami(e) {
				this.kaminum = e.target.value;
			},
			//数据交互
			onaction(num) {
				var that = this;
				var type = num;
				if (that.racheck === false) {
					uni.showModal({
						content: '请同意用户协议后操作',
						showCancel: false
					});
					return false;
				} else {

				uni.getStorage({
					key: 'user_infos',
					success: function(res) {
						var stystems = null;
						// #ifdef APP-PLUS
						uni.getSystemInfo({
							success: function(res) {
								if (res.platform == 'ios') {
									console.log('苹果机器');
									stystems = 'iphone';
								} else {
									console.log('不是苹果机器222');
									stystems = 'android';
								}
								console.log(res.platform);
							}
						});
						// #endif

						// #ifdef MP-WEIXIN
						stystems = 'miniprog';
						// #endif
						console.log(res);
						var uinfo = res.data;

						if (that.kahaonum == '') {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.卡号不能为空'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
							return false;
						}
						if (that.kaminum == '') {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.卡密不能为空'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
							return false;
						}

						that.https({
							url: jihuo_api,
							method: 'POST',
							data: {
								kahao: that.kahaonum,
								kami: that.kaminum,
								type: type
							},
							success: res => {
								console.log(res);
								//console.log(res.data.result_code);
								console.log(res.result_code);

								//激活时:-1 用户没有登录，-2 用户已禁用，-3卡号或卡蜜错误，-4卡号没有销售，-5卡号已经激活不可重复使用，-6卡号被禁用，-7 其他错误,0 成功
								if (res.result_code == -1) {
									//用户没有登录,让他微信登录
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.用户没有登录'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -2) {
									//用户已禁用
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.用户已禁用'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -3) {
									//卡号或卡密错误
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.卡号或卡密错误'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -4) {
									//-4卡号没有销售
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.卡号没有销售'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -5) {
									//-5卡号已经激活不可重复使用
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.卡号已经激活不可重复使用'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -6) {
									//-6卡号被禁用
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.卡号被禁用'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == -7) {
									//-7 其他错误
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.其他错误'),
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
									return false;
								}
								if (res.result_code == 0) {
									//成功
									uni.showModal({
										title: that.$t('jihuo.提示'),
										content: that.$t('jihuo.激活成功'),
										success: function(resg) {
											//先获取用户信息
											const value = uni.getStorageSync(
												'user_infos');
											var obj = JSON.parse(
												'{"openid":"' +
												value.openid +
												'","unionid": "' +
												value.unionid +
												'","kaishiriqi":"' +
												res.kaishiriqi +
												'","jieshuriqi":"' +
												res.jieshuriqi +
												'","userstatus":"' +
												res.userstatus +
												'","jihuofangshi":"' +
												value.jihuofangshi +
												'","nick_name":"' +
												value.nick_name +
												'","pic_url":"' +
												value.pic_url +
												'","uid":"' +
												value.uid +
												'","dailijibie":"' +
												res.dailijibie +
												'"}'
											);

											try {
												uni.setStorageSync('user_infos', obj);
												uni.reLaunch({
													url: "../index/start"
												})
											} catch (e) {
												// error
											}

											// uni.setStorage({
											//     key: 'user_infos',
											//     data: obj,
											//     success: function () {
											//         console.log('success');

											//     }
											// });
											//uni.setStorageSync('user_infos', obj);
										}
									});
								}
								// {
								// 	"result_msg": "",
								// 	"jieshuriqi": "0",
								// 	"jiehuofangshi": "0",
								// 	"userstatus": "0",
								// 	"dailijibie": "0",
								// 	"result_code": "-1",
								// 	"kaishiriqi": "0"
								// }
								//this.addresslist = res;
							},
							fail: err => {
								console.log(err);
								uni.showModal({
									title: '错误',
									content: "服务器出现错误：" + err,
									success: function(resw) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							},
							complete: function(eeee) {
								//console.log(eeee,'com')
							}
						});

						console.log(that.kaminum, that.kahaonum);
					},
					fail() {
						//返回登录按钮，重新微信登录
						uni.hideLoading();
					}
				});
				}
			},

			fontload(fontlang) {
				let fontclass = '';
				switch (fontlang) {
					case 'kz':
						fontclass = 'kz';
						break;
					case 'uy':
						fontclass = 'uy';
						break;
					default:
						fontclass = '';
				}
				return fontclass;
			},
			layout(item) {
				let className = '';
				switch (item) {
					case 'kz':
						className = 'kzlayout';
						break;
					case 'uy':
						className = 'uylayout';
						break;
					default:
						className = 'cn';
				}
				return className;
			},



			link: function(links) {
				var that = this;
				if (that.racheck === false) {
					uni.showModal({
						content: '请同意用户协议后操作',
						showCancel: false
					});
					return false;
				} else {
				if (links == 'ontrial') {
					if (that.cartype == 'jiashizheng') {
						uni.redirectTo({
							url: '/pages/index/index?ontrial=true'
						})
					} else {
						uni.redirectTo({
							url: '/pages/index/qualification?ontrial=true'
						})
					}
				} else if (links == 'buycode') {
					if (that.cartype == 'jiashizheng') {
						uni.redirectTo({
							url: '/pages/index/index?alert=1'
						})
					} else {
						uni.redirectTo({
							url: '/pages/index/qualification?alert=1'
						})
					}
				} else {
					uni.navigateTo({
						url: '/pages' + links
					})
				}
				}

			},
			tiyan() {
				var that = this;

			}
		}
	};
</script>

<style>
	page {
		background-color: #f5f6f5;
	}

	.loginview {
		width: 100%;
		height: 350rpx;
		background: #ffffff;
	}

	.loginbtnview {
		width: 700rpx;
		margin: 100rpx auto 0 auto;
		text-align: center;
	}

	.loginbtnk {
		width: 330rpx;
		margin: 10rpx;
		height: 120rpx;
		text-align: center;
		float: left;
		display: inline-block;
	}	
	/* .loginbtnk image{
		width: 100%;
		height: 80rpx;
		
	} */

	.weichat {
		color: #ffffff;
		background: #0bd34e;
	}

	.apple {
		color: #ffffff;
		width: 330rpx;
		/* background: #000000; */
		
		background-image: url('@/static/appleid_button.png');
		background-size: 100% 100%;
		/* border: #000000 1rpx solid; */
	}
	

	.logintxt {
		width: 700rpx;
		margin: 10rpx auto 0 auto;
	}

	.kzlayout .input-layout input {
		padding-right: 15rpx;
	}

	.uylayout .input-layout input {
		padding-right: 15rpx;
	}

	.cn {
		width: 80rpx;
	}

	.booter {
		position: fixed;
		width: 750rpx;
		text-align: center;
		bottom: 80rpx;
		left: 0rpx;
		height: 150rpx;
	}

	button {
		height: 80rpx;
		line-height: 80rpx;
	}

	.regulations {
		width: 750rpx;
		height: 60rpx;
		line-height: 60rpx;
		color: #ff3968;
	}

	/* #ifdef MP-WEIXIN */
	.payviewradio {
		display: inline-block;
		transform: scale(0.9);
	}

	/* #endif */

	/* #ifdef APP-PLUS || H5 */
	uni-radio .uni-radio-input {
		width: 20px !important;
		height: 20px !important;
		margin: 0 5px;
	}

	.payviewradio {
		display: inline-block;
	}

	uni-radio .uni-radio-input.uni-radio-input-checked {
		background: #0bd34e !important;
		border-color: #0bd34e !important;
	}

	uni-radio .uni-radio-input.uni-radio-input-checked:before {
		font-size: 16px !important;
	}

	/* #endif */
	.agree {
		width: 750rpx;
		height: 60rpx;
		line-height: 60rpx;

		flex-direction: row;
		align-items: center;
		text-align: center;
	}

	.agree label radio {
		display: inline-block;
	}

	.agree label {
		display: inline-block;
		color: #606266;
		line-height: 40rpx;
	}

	.activa {
		padding-top: 30%;
	}

	.activa_title {
		text-align: center;
		font-size: 40rpx;
		padding-bottom: 50rpx;
	}

	.two-button {
		width: 300rpx;
		display: inline-block;
	}

	.on-trial {
		width: 290rpx;
		border-radius: 10rpx;
		background-color: #82848a;
		color: #ffffff;
		margin-right: 10rpx;
	}

	.shopping {
		width: 300rpx;
		display: inline-block;
		position: relative;
	}

	.shopping-button {
		width: 290rpx;
		border-radius: 10rpx;
		background-color: #ff3968;

		color: #ffffff;
		margin-left: 10rpx;
		text-align: center;
	}

	.shopping-button_image {
		width: 78rpx;
		height: 60rpx;
		position: absolute;
		right: 10rpx;
		top: 10rpx;
	}

	.shopping text {
		display: inline-block;
		padding-right: 20rpx;
	}

	.button-agent {
		width: 600rpx;
		margin: 0rpx auto 10rpx auto;
		border-radius: 10rpx;
		background: #e5b064;
		color: #ffffff;
	}

	.button-group {
		width: 600rpx;
		margin: 20rpx auto;
		font-size: 25rpx;
	}

	.input-group {
		width: 600rpx;
		margin: 0 auto;
		border-radius: 10rpx;
		background-color: #ffffff;
		padding: 0rpx 30rpx;
	}

	.input-group label {
		min-width: 100rpx;
	}

	.input-layout {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 80rpx;
		line-height: 80rpx;
	}

	.border-b {
		border-bottom: 1rpx solid #d3d4d3;
	}

	.button-layout {
		width: 600rpx;
		margin: 30rpx auto 10rpx auto;
		border-radius: 10rpx;
		background: #19be6b;
		color: #ffffff;
	}

	.input-layout label {
		display: inline-block;
		height: 60rpx;
		line-height: 60rpx;
	}

	.input-layout input {
		display: inline-block;
		height: 60rpx;
		line-height: 60rpx;
	}

	.bg-purple {
		background-color: #18b566;
		width: 100%;
		height: 30rpx;
	}
</style>
